package org.example.hospital_registration_system.service;


import org.example.hospital_registration_system.mapper.IUserInfoMapper;
import org.example.hospital_registration_system.model.User;
import org.example.hospital_registration_system.utils.SecurityUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    @Autowired
    private IUserInfoMapper iUserInfoMapper;

    public User selectByUserName(String name){
        if(name !=null){
            User user = iUserInfoMapper.selectUserByUsername(name);
            if(user!=null){
                return user;
            }
        }
        return null;
    }

    public String enroll(User user) {
        User user1 = new User();
        user1.setUsername(user.getUsername());
        user1.setGender(user.getGender());
        user1.setPhone(user.getPhone());
        user1.setAddress(user.getAddress());
        String password = SecurityUtil.encrypt(user.getPassword());
        user1.setPassword(password);

        Integer n = iUserInfoMapper.insertUser(user1);
        if(n==1){
            return "注册成功";
        }else {
            return "注册失败";
        }
    }
}
